package com.xhtech.base.service.user.login

import com.xhtech.base.data.UserInfo
import com.xhtech.base.service.user.UserInfoManager
import com.xhtech.base.service.user.UserType

/**
 * @author yuanxh
 * @date :2023/6/30 12:18
 * @description:
 */
class UserLoginInfo : ILoginInfo {

    //用户类型 默认游客
    var userType = UserType.BEGGAR
    private var _userInfo: UserInfo? = null

    override fun getToken(): String? {
        return UserInfoManager.getInstances().getSaveToken()
    }

    override fun setLoginType(type: Int) {
        super.setLoginType(type)
        userType = when (type) {
            UserType.BEGGAR.type -> {
                UserType.BEGGAR
            }
            UserType.CIVILIAN.type -> {
                UserType.CIVILIAN
            }
            else -> {
                UserType.BEGGAR
            }
        }
    }

    override fun getLoginType(): UserType {
        return userType
    }

    override fun setUserInfo(userInfo: UserInfo) {
        _userInfo = userInfo
        UserInfoManager.getInstances().notifyDataChanged()
    }

    override fun getUserInfo(): UserInfo? {
        return _userInfo
    }

    override fun isLogin(): Boolean {
        var isLogin = true
        if (getToken().isNullOrEmpty()) {
            isLogin = false
        }
        if (UserInfoManager.getInstances().getSavePhone().isNullOrEmpty()) {
            isLogin = false
        }
        return isLogin
    }
}